class Solution(object):
    def nextGreatestLetter(self, letters, target):
        """
        :type letters: List[str]
        :type target: str
        :rtype: str
        """
        l = set(letters)
        min_v = float('inf')
        for c in l:
            if c != target:
                v = (ord(c) - ord(target)) % 26
                if v < min_v:
                    min_v = v
                    min_c = c
        return min_c



data = Solution()
letters = ["c", "f", "j"]
target = "a"
print(data.nextGreatestLetter(letters, target))
